package com.hht.tools.baselib

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.hht.baselibs.repository.BaseRepository
import com.hht.baselibs.viewModel.BaseViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext


/**
 * Author:chen'hu
 * Time:2024/6/17 16:10
 * Description:This is BaseLibViewModel
 */
class BaseLibViewModel:BaseViewModel() {
    override fun getRepository(): BaseRepository {
        return BaseLibRepository()
    }
    private val appList = MutableLiveData<List<AppBean>>()

    fun appListData():MutableLiveData<List<AppBean>>{
        viewModelScope.launch {
            appList.value=getAppList()
        }
        return appList
    }
    fun setBottomAppListData(){
        viewModelScope.launch {
            appList.value = getAppList()
        }
    }

    private suspend fun getAppList(): List<AppBean> {
        return withContext(Dispatchers.IO){
            ( mRepository as BaseLibRepository).getAppBeanList()
        }
    }
}